#!/usr/bin/env bash
#########################################################################
# File Name   : master-debug.sh
# Author      : seadog
# mail        : seadog0514@163.com
# Version     : 0.1
# Created Time: Wed 2024-10-02 09:51:00(+0800)
#########################################################################

# !!! monitor status
{
  watch 'openstack compute service list'
  watch 'openstack network agent list'
  watch 'openstack server list'
}

# !!! prepare log
{
  echo >/var/log/nova/nova-api.log
  echo >/var/log/nova/nova-compute.log
  echo >/var/log/neutron/neutron-server.log
  echo >/var/log/nova/nova-scheduler.log

  openstack server delete cirros01 || true

  netID=$(openstack --insecure network list | grep sharednet1 | awk '{ print $2 }')
  openstack --insecure server create --flavor m1.tiny --image cirros-0.6.3 --security-group secgroup01 --nic net-id=$netID --key-name mykey cirros01

  sleep 3

  cp /var/log/nova/nova-api.log .
  cp /var/log/nova/nova-compute.log .
  cp /var/log/nova/nova-scheduler.log .
  cp /var/log/neutron/neutron-server.log .

  python3 -m http.server 1888

  # !!@ retrieve logs

  # http://192.168.0.81:1888/neutron-server.log
  # http://192.168.0.81:1888/neutron.conf
  # http://192.168.0.81:1888/neutron_ovn_metadata_agent.ini
  # http://192.168.0.81:1888/nova-api.log
  # http://192.168.0.81:1888/nova-compute.log
  # http://192.168.0.82:1888/neutron_ovn_metadata_agent.ini
  # http://192.168.8.150:1888/nova-api.log

  rm -rf *.log.* || true
  rm -rf *.log || true

  wget http://192.168.0.81:1888/nova-api.log
  wget http://192.168.0.81:1888/nova-compute.log
  wget http://192.168.0.81:1888/nova-scheduler.log
  wget http://192.168.0.81:1888/neutron-server.log

  # nova-api.log
  # nova-compute.log
  # nova-scheduler.log
  # neutron-server.log
}
